// 将树铺成一维数组
var list1 = [{
    id: "ab",
    children: [{
        id: "cd",
        children: [{
            id: "ef",
            children: []
        }]
    }]
},{
    id: "ab1",
    children: [{
        id: "cd1",
        children: [{
            id: "ef1",
            children: []
        }]
    }]
}]
const result = [];
function dfs (node) {
    const children = node.children;
    for (let i = 0; i < children.length; i++) {
        const child = children[i];
        child.parent = node;
        // console.log(child)
        result.push(child);
        if (child.children && child.children.length > 0) {
            dfs(child);
        }
    }
}
for (let i = 0; i < list1.length; i++) {
    result.push(list1[i]);
    dfs(list1[i]);
}
console.log(result)
function find (value) {
    const node = result.find(item => item.id === value);
    if (node) {
        let path = node.id;
        let temp = node;
        while (temp.parent) {
            path = temp.parent.id + ' -> ' + path;
            temp = temp.parent;
        }
        return path
    }
}

console.log(find('ef'))
